const { UserDao } = require("../dao/user_dao")

class UserService {

    constructor() {
        this.userDao = new UserDao()
    }

    // 登录
    login(name, password) {
        return this.userDao.getTbUserByName(name, password)
    }

    // 注册
    register(tbUser) {
        return this.userDao.insert(tbUser)
    }

    // 查询
    getTbUsers() {
        return this.userDao.getTbUsers()
    }

    // 保存
    save(tbUser) {
        return tbUser.id === undefined
            ? this.userDao.insert(tbUser)
            : this.userDao.update(tbUser)
    }

    // 删除
    delete(id) {
        return this.userDao.delete(id)
    }

}

module.exports = {
    UserService
}